import { ExtBigIdTuple, INTEGER_PG, VARCHAR255_PG } from "~/db.pg";
import { ExtSkuTpl, Tradable } from "~/extend";

import { ExtOwner } from "@/stream-user/core.define";

import { Stockable } from "@/river-stock/core.define";
import { ENUM_TON_ORDER } from "@/river-ton/core.define";
import { TonOrder, TonOrderGroup } from "@/river-ton/schema.order";

/** 订单商品（下面是从后到前的查询位）
 * @s1 管理员
 * @s2 创建人
 * @s3 联系人
 * @s4 订单集合
 * @s5 订单
 * @s6 材料重量库存
 */
export type TonSku = ExtBigIdTuple &
  ExtOwner &
  ExtSkuTpl &
  Tradable &
  Stockable & {
    /** 公式名称 */
    formulaName: VARCHAR255_PG;
    /** 公式内容 */
    formulaContent: VARCHAR255_PG;

    type: ENUM_TON_ORDER;
    ton: INTEGER_PG;
    isTonAble: boolean;
    isOrderDisabled: boolean;
  } & {
    refTonOrderGroupId: TonOrderGroup["id"];
    justTonOrderGroup?: TonOrderGroup;

    refTonOrderId: TonOrder["uuid32"];
    justTonOrder?: TonOrder;
  };

export type TonSkuJoinLsKey = "justOwner" | "justCreator" | "justContact" | "justTonOrderGroup" | "justTonOrder";

export const TonSkuJoinLs: TonSkuJoinLsKey[] = ["justOwner", "justCreator", "justContact", "justTonOrderGroup", "justTonOrder"];
